<!--
 * @Description: 数据统计
 * @Author: pinus
 * @Email: pinus0716@163.com
 * @Git: https://gitee.com/xyf97
 * @Date: 2021-10-02 21:13:16
 * @LastEditTime: 2021-10-02 21:45:21
-->
<template>
  <div class="stat-container">
    <!--  头部面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/wlecome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 内容card -->
    <el-card>
      <div id="myReport"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'

export default {
  name: 'State',
  data() {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },

  // ? echart必须在dom元素挂在好后才能使用
  async mounted() {
    const { data: res } = await this.$http.get('reports/type/1')

    console.log(res)
    if (res.meta.status !== 200) {
      return this.$message.error(res.meta.msg)
    }
    this.optionsData = res.data

    // 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.getElementById('myReport'))

    // 合并对象
    const result = _.merge(res.data, this.options)

    // 绘制图表
    myChart.setOption(result)
  }
}
</script>

<style lang="less" scoped>
#myReport {
  width: 800px;
  height: 600px;
  margin: 0 auto;
}
</style>
